#include "BaseType.h"
#include "Tracer.h"
using namespace std;
using namespace libemb;

/**
 * 模板方法：
 * 1.定义好算法的框架，将一些步骤的实现延迟到子类实现
 * 适用场景：
 * 1.
 * 2.
 **/

//图像压缩模板
class ImageCompress{
DECL_CLASSNAME(ImageCompress)
public:
    virtual void readImage()=0;//延迟到子类实现
    virtual void saveImage()=0;//延迟到子类实现
    virtual void doCompress()//允许子类重写
    {
        TRACE_INFO_CLASS("Compress image.");
    }
    //压缩图片:不允许子类重写
    virtual void compress() final
    {
        readImage();
        doCompress();
        saveImage();
    }
};

//JPEG压缩
class JpegCompress:public ImageCompress{
DECL_CLASSNAME(JpegCompress)
public:
    void readImage() override
    {
        TRACE_INFO_CLASS("read jpeg.");
    }
    void saveImage() override
    {
        TRACE_INFO_CLASS("save jpeg.");
    }
};


int main()
{
    Tracer::getInstance().setLevel(TRACE_LEVEL_DBG);
	Tracer::getInstance().addSink(std::make_shared<STDSink>()).start();

    JpegCompress compress;
    compress.compress();

    return RC_OK;
}